﻿using System;
using System.Collections.Generic;
using System.Text;

namespace 解释器模式
{
    class Usa : PeopleInterpreter
    {
        private Dictionary<char, string> dic = new Dictionary<char, string>();

        public Usa()
        {
            dic.Add('u',"美国人");
            dic.Add('s',"用");
            dic.Add('a',"刀叉吃饭");
        }


        public override void Conversion(Context context)
        {
            Console.WriteLine(this.GetType().ToString()+"业务");

            string text = context.Get();
            if (string.IsNullOrEmpty(text))
            {
                return;
            }
            List<string> strList = new List<string>();
            foreach(var item in text.ToLower().ToCharArray())
            {
                if (dic.ContainsKey(item))
                {
                    strList.Add(dic[item]);
                }
                else
                {
                    strList.Add(item.ToString());
                }
            }
            context.Set(string.Concat(strList));
        }
    }
}
